#!/usr/bin/python3
# -*- coding: utf8 -*-
# Date   : 2021/07/20
# Author : Kwan
# Email  : allenxian@live.com
# Blog   : https://my.oschina.net/u/4173440

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_socketio import SocketIO
from flask_qrcode import QRcode


class DefaultEvn:
    DEBUG = False
    CSRF_ENABLED = True
    SECRET_KEY = 'bbd0b605567360b4'
    SQLALCHEMY_DATABASE_URI = 'sqlite:///database/pycarpark.db'
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    JSONIFY_PRETTYPRINT_REGULAR = True
    JSONIFY_MIMETYPE = 'application/json'


def create_app():
    """
    生成应用
    """
    app = Flask(__name__)
    try:
        app.config.from_json("config/app.json")
    except Exception as e:
        print(f"加载应用配置错误，启用默认环境:{e}")
        app.config.from_object(DefaultEvn)
    return app


app = create_app()
db = SQLAlchemy(app)
socketio = SocketIO(app)
qrcode = QRcode(app)